package com.mgface.thymeleaf.exception;

import org.apache.commons.lang.StringUtils;

/**
 * thymeleaf项目的父类
 * 
 * @author yuxiang
 *
 */
public abstract class ThymeleafException extends RuntimeException {
	private static final long serialVersionUID = 4389198222617913057L;
	// 异常代码
	public int code = 0;
	// 异常描述
	public String description = "";

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public ThymeleafException() {
		super();
	}

	public ThymeleafException(String message) {
		super(message);
		this.description = message;
	}

	public ThymeleafException(int code, String message) {
		super(message);
		this.code = code;
		this.description = message;
	}
	
	// 附加内容
	public abstract String explain();

	@Override
	public String toString() {
		String body = "异常代码[" + this.code + "],异常描述[" + this.description + "]";
		if(StringUtils.isNotBlank(this.explain())){
			body+=",说明["+this.explain()+"]";
		}
		return body;
	}
}
